﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace Obsidian.Input
{
    public enum MouseButton 
    {
        Left,
        Right,
        Middle,
    }

    /// <summary>
    /// Gets input from the InputManager and provides a simple method to poll input without having to handle any binding.
    /// </summary>
    public class OldInput
    {
        /// <summary>
        /// The current mouse position in pixel coordinates. (Read Only)
        /// </summary>
        public static Vector2 MousePosition { get; internal set; }

        /// <summary>
        /// Is any key or mouse button currently held down? (Read Only)
        /// </summary>
        public static bool AnyKey { get; internal set; }

        /// <summary>
        /// Returns true the first frame the user hits any key or mouse button (Read Only).
        /// </summary>
        public static bool AnyKeyDown { get; internal set; }

        /// <summary>
        /// Returns the value of the virtual axis identified by axisName.
        /// </summary>
        /// <param name="axisName"></param>
        /// <returns></returns>
        public static float GetAxis(string axisName)
        {
            if (InputManager.axesMap.ContainsKey(axisName))
            {
                // we need to return the axis with the greatest amount of input
                float value = InputManager.axesMap[axisName][0].Value;
                for (int i = 1; i < InputManager.axesMap[axisName].Count; i++)
                {
                    var other = InputManager.axesMap[axisName][i].Value;
                    if (value < other)
                        value = other;
                }
                // TODO - Apply filtering?
                return value;
            }
            else throw new Exception(); // should we throw an exception? or just return 0
        }

        /// <summary>
        /// Returns the value of the virtual axis identified by axisName with no smooth filtering applied.
        /// </summary>
        /// <param name="axisName"></param>
        /// <returns></returns>
        public static float GetAxisRaw(string axisName)
        {
            if (InputManager.axesMap.ContainsKey(axisName))
            {
                // we need to return the axis with the greatest amount of input
                float value = InputManager.axesMap[axisName][0].Value;
                for (int i = 1; i < InputManager.axesMap[axisName].Count; i++)
                {
                    var other = InputManager.axesMap[axisName][i].Value;
                    if (value < other)
                        value = other;
                }
                return value;
            }
            else throw new Exception(); // should we throw an exception? or just return 0
        }

        /// <summary>
        /// Returns true while the virtual button identified by buttonName is held down.
        /// </summary>
        /// <param name="buttonName"></param>
        /// <returns></returns>
        public static bool GetButton(string buttonName)
        {
            throw new NotImplementedException();
        }

        /// <summary>
        /// Returns true during the frame the user pressed down the virtual button identified by buttonName.
        /// </summary>
        /// <param name="buttonName"></param>
        /// <returns></returns>
        public static bool GetButtonDown(string buttonName)
        {
            throw new NotImplementedException();
        }

        /// <summary>
        /// Returns true during the frame the user releases the virtual button identified by buttonName.
        /// </summary>
        /// <param name="buttonName"></param>
        /// <returns></returns>
        public static bool GetButtonUp(string buttonName)
        {
            throw new NotImplementedException();
        }

        public static bool GetKey(string buttonName)
        {
            throw new NotImplementedException();
        }

        public static bool GetKeyDown(string buttonName)
        {
            throw new NotImplementedException();
        }

        public static bool GetKeyUp(string buttonName)
        {
            throw new NotImplementedException();
        }

        public static bool GetMouseButton(MouseButton button)
        {
            throw new NotImplementedException();
        }

        public static bool GetMouseButtonDown(MouseButton button)
        {
            throw new NotImplementedException();
        }

        public static bool GetMouseButtonUp(MouseButton button)
        {
            throw new NotImplementedException();
        }

        /// <summary>
        /// Resets all input. After ResetInputAxes all axes return to 0 and all buttons return to 0 for one frame.
        /// </summary>
        public static void ResetInputAxes()
        {

        }
    }
}